var t = require;
var e = module;
var o = exports;
var i = this && this.__awaiter ||
function(t, e, o, i) {
    return new(o || (o = Promise))(function(n, a) {
        function r(t) {
            try {
                l(i.next(t))
            } catch(e) {
                a(e)
            }
        }
        function s(t) {
            try {
                l(i.
                throw (t))
            } catch(e) {
                a(e)
            }
        }
        function l(t) {
            var e;
            t.done ? n(t.value) : (e = t.value, e instanceof o ? e: new o(function(t) {
                t(e)
            })).then(r, s)
        }
        l((i = i.apply(t, e || [])).next())
    })
},
n = this && this.__generator ||
function(t, e) {
    var o, i, n, a, r = {
        label: 0,
        sent: function() {
            if (1 & n[0]) throw n[1];
            return n[1]
        },
        trys: [],
        ops: []
    };
    return a = {
        next: s(0),
        throw: s(1),
        return: s(2)
    },
    "function" == typeof Symbol && (a[Symbol.iterator] = function() {
        return this
    }),
    a;
    function s(t) {
        return function(e) {
            return l([t, e])
        }
    }
    function l(a) {
        if (o) throw new TypeError("Generator is already executing.");
        for (; r;) try {
            if (o = 1, i && (n = 2 & a[0] ? i.
            return: a[0] ? i.
            throw || ((n = i.
            return) && n.call(i), 0) : i.next) && !(n = n.call(i, a[1])).done) return n;
            switch (i = 0, n && (a = [2 & a[0], n.value]), a[0]) {
                case 0:
                case 1:
                    n = a;
                break;
                case 4:
                    return r.label++,
                {
                    value: a[1],
                    done: !1
                };
                case 5:
                    r.label++,
                i = a[1],
                a = [0];
                continue;
                case 7:
                    a = r.ops.pop(),
                r.trys.pop();
                continue;
                default: if (! (n = (n = r.trys).length > 0 && n[n.length - 1]) && (6 === a[0] || 2 === a[0])) {
                    r = 0;
                    continue
                }
                if (3 === a[0] && (!n || a[1] > n[0] && a[1] < n[3])) {
                    r.label = a[1];
                    break
                }
                if (6 === a[0] && r.label < n[1]) {
                    r.label = n[1],
                    n = a;
                    break
                }
                if (n && r.label < n[2]) {
                    r.label = n[2],
                    r.ops.push(a);
                    break
                }
                n[2] && r.ops.pop(),
                r.trys.pop();
                continue;
            }
            a = e.call(t, r)
        } catch(s) {
            a = [6, s],
            i = 0
        } finally {
            o = n = 0
        }
        if (5 & a[0]) throw a[1];
        return {
            value: a[0] ? a[1] : void 0,
            done: !0
        }
    }
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var a = t("GlobalUserData"),
r = t("ChannelTool"),
s = t("Util"),
l = function() {
    function t() {
        this.video_hw = {
            ad: null,
            isLoad: !1
        },
        this.videoId = "p1x8iuykm3",
        this.bannersId = ["x9ywoiop38", "p2x5ku528g"],
        this.bannerAds = [],
        this.bannerId = 0,
        this.bannerAd = null,
        this.refreshId = 0,
        this.bannerAdColdTime = 0,
        this.isHideRefreshBanner = !1,
        this.interAdColdTime = 0,
        this.nativeInsertAdObj = {
            nativeAd: null,
            adNode: null,
            nativeAdItem: null
        },
        this.nativeId = "m89ianqfr9",
        this.bg = null,
        this.lastLoadTimer = 0,
        this.is_click_img = !1
    }
    return Object.defineProperty(t, "Ins", {
        get: function() {
            return null == this._instance && (this._instance = new t),
            this._instance
        },
        enumerable: !1,
        configurable: !0
    }),
    t.prototype.init = function() {
        var t = this;
        s.Util.is_qg() && (console.log("初始化华为平台"), this.systemInfo = qg.getSystemInfoSync(), qg.onHide(function() {
            console.log("切后台")
        }), qg.onShow(function() {
            console.log("切回前台"),
            t.nativeInsertAdObj.adNode && t.reportNativeAdShow(t.nativeInsertAdObj.nativeAd, t.nativeInsertAdObj.nativeAdItem.adId)
        }))
    },
    t.prototype.gameLogin = function(e) {
        var o = this;
        this._success = e,
        s.Util.is_qg() ? qg.gameLoginWithReal({
            forceLogin: 1,
            appid: "106412127",
            success: function(o) {
                t.Ins.init_reward_video(),
                t.Ins.init_banner(),
                e && e(),
                console.log(" game login with real success:" + JSON.stringify(o))
            },
            fail: function(t, e) {
                console.log("game login with real fail:" + t + ", code:" + e),
                7004 != e && 2012 != e || (console.log("玩家取消登录，返回游戏界面让玩家重新登录。"), setTimeout(function() {
                    o.gameLogin(o._success)
                },
                1e3)),
                7021 == e && (console.log("The player has canceled identity verification. Forbid the player from entering the game."), setTimeout(function() {
                    s.Util.exitApplication()
                },
                2e3))
            }
        }) : e()
    },
    t.prototype.exitApplication = function() {
        qg.exitApplication({
            success: function() {
                console.log("exitApplication success")
            },
            fail: function() {
                console.log("exitApplication fail")
            },
            complete: function() {
                console.log("exitApplication complete")
            }
        })
    },
    t.prototype.init_reward_video = function() {
        var t = this;
        s.Util.is_qg() && null == this.video_hw.ad && (this.video_hw.ad = hbs.createRewardedVideoAd({
            adUnitId: this.videoId,
            success: function() {
                console.log("createRewardedVideoAd: success")
            },
            fail: function(t, e) {
                console.log("createRewardedVideoAd fail: " + t + "," + e)
            }
        }), this.video_hw.ad.onLoad(function() {
            t.video_hw.isLoad = !0
        }), this.video_hw.ad.load())
    },
    t.prototype.showVideoAd = function(t, e, o) {
        var i = this;
        this.video_hw.isLoad ? (this.video_hw.ad.show(), this.video_hw.isLoad = !1) : this.video_hw.ad.load();
        var n = function() {
            o && o(),
            i.video_hw.ad.offError(n)
        };
        this.video_hw.ad.onError(n);
        var a = function(o) {
            o.isEnded ? t && t() : e && e(),
            i.video_hw.ad.load(),
            i.video_hw.ad.offClose(a)
        };
        this.video_hw.ad.onClose(a)
    },
    t.prototype.init_banner = function() {
        var t = this;
        if (s.Util.is_qg()) {
            this.systemInfo.safeArea.width;
            for (var e = this.systemInfo.safeArea.height,
            o = function(o) {
                var n = i.bannersId[o],
                a = function() {
                    cc.log("banner加载完成"),
                    s.offLoad(a)
                },
                r = function() {
                    s.offError(r)
                },
                s = hbs.createBannerAd({
                    adUnitId: n,
                    adIntervals: 60,
                    style: {
                        top: e - 57,
                        left: 0,
                        height: 57,
                        width: 360
                    }
                });
                s.onClose(function() {
                    console.log("HuaWei banner 广告关闭"),
                    t.bannerAdColdTime = new Date().getTime()
                }),
                s.offError(r),
                s && s.onError(r),
                s.onLoad(a),
                i.bannerAds.push(s)
            },
            i = this, n = 0; n < this.bannersId.length; n++) o(n)
        }
    },
    t.prototype.refreshBanner = function(t) {
        return void 0 === t && (t = !0),
        i(this, void 0, void 0,
        function() {
            var t, e, o, i = this;
            return n(this,
            function(n) {
                switch (n.label) {
                    case 0:
                        return this.isHideRefreshBanner = !1,
                    this.systemInfo.safeArea.width,
                    t = this.systemInfo.safeArea.height,
                    e = this.bannersId[this.refreshId],
                    o = hbs.createBannerAd({
                        adUnitId: e,
                        adIntervals: 60,
                        style: {
                            top: t - 57,
                            left: 0,
                            height: 57,
                            width: 360
                        }
                    }),
                    [4, new Promise(function(t) {
                        var e = function() {
                            console.log("banner" + i.refreshId + " 刷新成功"),
                            o.offLoad(e),
                            i.bannerAds[i.refreshId] = o,
                            i.refreshId,
                            i.refreshId++,
                            i.refreshId >= i.bannerAds.length && (i.refreshId = 0),
                            t("success")
                        };
                        o.onLoad(e),
                        o.onClose(function() {
                            console.log("HuaWei banner 广告关闭2"),
                            i.bannerAdColdTime = new Date().getTime()
                        })
                    })];
                    case 1:
                        return n.sent(),
                    [2];
                }
            })
        })
    },
    t.prototype.show_banner = function(t, e) {
        void 0 === t && (t = !1),
        void 0 === e && (e = !1),
        new Date().getTime() - this.bannerAdColdTime < 6e4 || (this.hide_banner(), this.bannerAd = this.bannerAds[this.bannerId], this.bannerId++, this.bannerId >= this.bannerAds.length && (this.bannerId = 0), this.bannerAd.show())
    },
    t.prototype.hide_banner = function() {
        this.isHideRefreshBanner = !0,
        this.bannerAd && this.bannerAd.hide()
    },
    t.prototype.showInsertAd = function() {
        if (! (new Date().getTime() - this.interAdColdTime < 6e4)) {
            console.log("showInsertAd");
            var t = this;
            this.interstitialAd = qg.createInterstitialAd({
                adUnitId: "u5w0nm6dao"
            }),
            this.interstitialAd.onError(function(t) {
                console.log("插屏广告加载失败", t)
            }),
            this.interstitialAd.onClose(function() {
                console.log("interstitialAd closed")
            }),
            this.interstitialAd.load(),
            this.interstitialAd.onLoad(function() {
                t.interAdColdTime = new Date().getTime(),
                t.interstitialAd.show()
            })
        }
    },
    t.prototype.hideInsertAd = function() {
        this.interstitialAd && this.interstitialAd.hide()
    },
    t.prototype.showNativeInsertAd = function() {
        r.ChannelTool.curentChannel == r.ChannelTool.ChannelEnum.HW && (console.log("创建华为原生广告"), this.showNative(this.nativeInsertAdObj, this.nativeId, "prefab/hwnativeInsertAd", !0, null, null,
        function() {}))
    },
    t.prototype.hideNativeInsertAd = function() {
        this.bg && this.bg.destroy(),
        this.bg = null,
        this.nativeInsertAdObj.adNode && this.nativeInsertAdObj.adNode.destroy(),
        this.nativeInsertAdObj.adNode = null
    },
    t.prototype.showNative = function(t, e, o, r, l, c, d, h) {
        return void 0 === r && (r = !1),
        void 0 === h && (h = !1),
        i(this, void 0, void 0,
        function() {
            var h, p, u, f, m = this;
            return n(this,
            function(_) {
                switch (_.label) {
                    case 0:
                        return t.nativeAd || (t.nativeAd = qg.createNativeAd({
                        adUnitId: e,
                        success: function() {
                            console.log("loadNativeAd loadNativeAd : success")
                        },
                        fail: function(t, e) {
                            console.log("loadNativeAd loadNativeAd fail: " + t + "," + e)
                        },
                        complete: function() {
                            console.log("loadNativeAd loadNativeAd : complete")
                        }
                    }), console.log("创建原生广告")),
                    t.adNode ? [3, 2] : (h = t, [4, s.Util.getPrefabNode(o)]);
                    case 1:
                        h.adNode = _.sent(),
                    cc.director.getScene().getChildByName("Canvas").addChild(t.adNode, 9999),
                    _.label = 2;
                    case 2:
                        return r || (t.adNode.scale = cc.view.getVisibleSize().width / 1280),
                    p = t.adNode.getChildByName("image").getComponent(cc.Sprite),
                    t.adNode.active = !1,
                    t.nativeAdItem && t.nativeAdItem.imgUrlList[0] && (t.adNode.getChildByName("bar").getChildByName("title").getComponent(cc.Label).string = t.nativeAdItem.title + ":" + t.nativeAdItem.source, s.Util.loadImg(p, t.nativeAdItem.imgUrlList[0],
                    function() {
                        return i(m, void 0, void 0,
                        function() {
                            var e, o, i = this;
                            return n(this,
                            function(n) {
                                switch (n.label) {
                                    case 0:
                                        return this.is_click_img = !1,
                                    t.adNode && (t.adNode.active = !0),
                                    this.reportNativeAdShow(t.nativeAd, t.nativeAdItem.adId),
                                    !r || this.bg ? [3, 2] : (e = this, [4, s.Util.getPrefabNode("prefab/bg")]);
                                    case 1:
                                        e.bg = n.sent(),
                                    cc.director.getScene().getChildByName("Canvas").addChild(this.bg, 9998),
                                    n.label = 2;
                                    case 2:
                                        return o = a.default.nTotalGame % 6,
                                    s.Util.is_qg() && !a.default.bAuditMode && a.default.nativeMistakeBannerList[o] && l && (l.active = !0),
                                    c && c(),
                                    t.adNode.getChildByName("btn_close").on("touchend",
                                    function() {
                                        t.adNode && (t.adNode.destroy(), t.adNode = null),
                                        i.bg && i.bg.destroy(),
                                        i.bg = null,
                                        d && d()
                                    }),
                                    p.node.on("touchend",
                                    function() {
                                        i.reportNativeAdClick(t.nativeAd, t.nativeAdItem.adId)
                                    }),
                                    [2];
                                }
                            })
                        })
                    })),
                    u = function(e) {
                        t.nativeAd.offLoad(u);
                        var o = e.adList.pop();
                        t.adNode.getChildByName("bar").getChildByName("title").getComponent(cc.Label).string = o.title + ":" + o.source,
                        m.reportNativeAdShow(t.nativeAd, o.adId),
                        s.Util.loadImg(p, o.imgUrlList[0],
                        function() {
                            return i(m, void 0, void 0,
                            function() {
                                var e, i, h = this;
                                return n(this,
                                function(n) {
                                    switch (n.label) {
                                        case 0:
                                            return this.is_click_img = !1,
                                        t.nativeAdItem = o,
                                        t.adNode && (t.adNode.active = !0),
                                        !r || this.bg ? [3, 2] : (e = this, [4, s.Util.getPrefabNode("prefab/bg")]);
                                        case 1:
                                            e.bg = n.sent(),
                                        cc.director.getScene().getChildByName("Canvas").addChild(this.bg, 9998),
                                        n.label = 2;
                                        case 2:
                                            return i = a.default.nTotalGame % 6,
                                        s.Util.is_qg() && !a.default.bAuditMode && a.default.nativeMistakeBannerList[i] && l && (l.active = !0),
                                        c && c(),
                                        p.node.off("touchend"),
                                        p.node.on("touchend",
                                        function() {
                                            h.reportNativeAdClick(t.nativeAd, t.nativeAdItem.adId)
                                        }),
                                        t.adNode.getChildByName("btn_close").off("touchend"),
                                        t.adNode.getChildByName("btn_close").on("touchend",
                                        function() {
                                            t.adNode && (t.adNode.destroy(), t.adNode = null),
                                            d && d(),
                                            h.bg && h.bg.destroy(),
                                            h.bg = null
                                        }),
                                        [2];
                                    }
                                })
                            })
                        })
                    },
                    t.nativeAd && (this.lastLoadTimer = new Date().getTime(), t.nativeAd.load(), t.nativeAd.offLoad(u), t.nativeAd.onLoad(u), f = function(e) {
                        console.log(e),
                        t.nativeAd.offLoad(u),
                        t.nativeAd.offError(f)
                    },
                    t.nativeAd.offError(f), t.nativeAd.onError(f)),
                    [2];
                }
            })
        })
    },
    t.prototype.vibrateLong = function() {
        qg.vibrateLong({})
    },
    t.prototype.vibrateShort = function() {
        qg.vibrateShort({})
    },
    t.prototype.reportNativeAdShow = function(t, e) {
        if (this.is_click_img) return this.is_click_img = !1,
        void this.hideNativeInsertAd();
        t && e && (console.log("上报原生展示"), t.reportAdShow({
            adId: e
        }))
    },
    t.prototype.reportNativeAdClick = function(t, e) {
        t && e && (this.is_click_img = !0, t.reportAdClick({
            adId: e
        }))
    },
    t._instance = null,
    t
} ();
o.default = l